﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using DAL;
using Entities;
using BUS;
using Utility;

public partial class Administrator_sanpham_Detail : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            load_data();
            Session["tranghientai"] = Request.QueryString.ToString();
        }
    }

     private void load_data()
    {
        int id = int.Parse(Request.QueryString["id"].ToString());
        Tbl_SanPham_Entities sp = Tbl_SanPham_BUS.GetByID(id);
        lit_masp.Text = sp.MaSP.ToString();
        lit_tensp.Text = sp.TenSP;
        Tbl_LoaiSP_Entities lsp = Tbl_LoaiSP_BUS.GetByID(sp.LoaiSP);
        lit_loaisp.Text = lsp.TenLoai;
        Tbl_DoanhNghiep_Entities dn = Tbl_DoanhNghiep_BUS.GetByID(sp.DoanhNghiep);
        lit_doanhnghiep.Text = dn.TenDN;
        lit_giagoc.Text = sp.GiaGoc.ToString();
        lit_giaban.Text = sp.GiaBan.ToString();
        lit_tylegiamgia.Text = (100 - (sp.GiaBan * 100 / sp.GiaGoc)).ToString();
        lit_ngaydang.Text = sp.NgayDang;
        lit_thoigiansudung.Text = sp.ThoiGianSuDung;
        ftxt_thongtinsp.Text = sp.ThongTinCoBan;
        ftxt_dksd.Text = sp.DKSD;
        lit_slb.Text = sp.SLBan.ToString();
        lit_tt.Text = sp.TinhTrang;
        load_image();
        hyp_themhinh.NavigateUrl = "~/Administrator/Image_Add.aspx?id=" + sp.STT.ToString();
    }

    private void load_image()
    {
        int id = int.Parse(Request.QueryString["id"]);
        Tbl_ImageSP_Collection imgsp = Tbl_ImageSP_BUS.GetByID(id);
        DataList1.DataSource = imgsp;
        DataList1.DataBind();
    }

    protected void DataList1_ItemDataBound(object sender, DataListItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
        {

            Tbl_ImageSP_Entities hinh = (Tbl_ImageSP_Entities)e.Item.DataItem;
            Image imgsp = (Image)e.Item.FindControl("imgsp");
            imgsp.ImageUrl = "~/Photos/Thumbs/" + hinh.ImagePath;

            HyperLink xoa_img = (HyperLink)e.Item.FindControl("xoa_img");
            xoa_img.NavigateUrl = "~/Administrator/xoahinh.aspx?tenhinh=" + hinh.ImagePath;
        }
    }

}

   

